package com.atguigu.gmall.product.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * sku商品上下架rabbitmq配置
 */
@Configuration
public class SkuRabbitConfig {
    /**
     * 新建交换机
     */
    @Bean("skuExchange")
    public Exchange skuExchange(){
        return ExchangeBuilder.directExchange("sku_exchange").build();
    }
    /**
     * 新建队列:下架
     */
    @Bean("skuQueue1")
    public Queue skuQueue1(){
        return QueueBuilder.durable("sku_queue_1").build();
    }
    /**
     * 新建队列：上架
     */
    @Bean("skuQueue2")
    public Queue skuQueue2(){
        return QueueBuilder.durable("sku_queue_2").build();
    }

    /**
     * 新建绑定:下架
     */
    @Bean
    public Binding skuBinding1(@Qualifier("skuExchange") Exchange skuExchange,
                             @Qualifier("skuQueue1") Queue skuQueue1){
        return BindingBuilder.bind(skuQueue1).to(skuExchange).with("sku.down").noargs();
    }

    /**
     * 新建绑定：上架
     */
    @Bean
    public Binding skuBinding2(@Qualifier("skuExchange") Exchange skuExchange,
                              @Qualifier("skuQueue2") Queue skuQueue2){
        return BindingBuilder.bind(skuQueue2).to(skuExchange).with("sku.upper").noargs();
    }
}
